package com.example.xgakj.securityguard.ui.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.example.xgakj.mylibrary.mvp.utils.CommonUtil;
import com.example.xgakj.mylibrary.mvp.utils.ToastUtil;
import com.example.xgakj.securityguard.R;
import com.example.xgakj.securityguard.base.BaseActivity;
import com.example.xgakj.securityguard.models.LoginModel;
import com.qmuiteam.qmui.util.QMUIViewHelper;
import com.qmuiteam.qmui.widget.QMUITopBar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class LoginActivity extends BaseActivity {

    @BindView(R.id.ed_name)
    EditText edName;
    @BindView(R.id.ed_password)
    EditText edPassword;
    @BindView(R.id.btn_login)
    Button btnLogin;
    @BindView(R.id.topbar)
    QMUITopBar topbar;
    private String user;
    private String passWord;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        ButterKnife.bind(this);
        initTopBar();
    }

    private void initTopBar() {
        topbar.setTitle("登录");
        topbar.addLeftBackImageButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        topbar.addRightTextButton("配置", QMUIViewHelper.generateViewId())
                .setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent=new Intent(LoginActivity.this,ServerIPActivity.class);
                        startActivity(intent);
                        overridePendingTransition(R.anim.slide_still, R.anim.slide_out_right);
                    }
                });
    }

    @OnClick(R.id.btn_login)
    public void onViewClicked() {
        user = edName.getText().toString().trim();
        passWord = edPassword.getText().toString().trim();
        if (!CommonUtil.isNull(user) && !CommonUtil.isNull(passWord)) {
            LoginModel loginModel = new LoginModel();
            loginModel.login(user, passWord);
        } else {
            ToastUtil.showShort(mContex, "请输入正确的账号密码");
        }
    }
}
